<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video
          controls
          :src="mvVIDEO"
        ></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="detail.cover" alt="" />
          </div>
          <span class="name">{{detail.artistName}}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{detail.name}}</h2>
          <span class="date">{{detail.publishTime}}</span>
          <span class="number">播放：{{detail.playCount | playNumFormat}}次</span>
          <p class="desc">{{detail.desc}}</p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap" v-if="hotComments !== undefined && hotComments.length !== 0">
        <p class="title">精彩评论<span class="number">({{ hotComments.length }})</span></p>
        <div class="comments-wrap">
          <div class="item"
          v-for="item in hotComments"
          :key="item.id"
          >
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length != 0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">最新评论<span class="number">({{total}})</span></p>
        <div class="comments-wrap">
          <div class="item"
          v-for="item in comments"
          :key="item.id"
          >
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length != 0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">{{item.time | transDate}}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :limit="limit"
      >
      </el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item"
          v-for="item in mvs"
          :key="item.id"
          >
            <div class="img-wrap">
              <img :src="item.cover" alt="" />
              <span class="iconfont icon-play"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{item.playCount | playNumFormat}}</div>
              </div>
              <span class="time">{{item.duration}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{item.name}}</div>
              <div class="singer">{{item.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { MVURL, MVSIMI, MVDetail,MVcomment } from '../network/request'
export default {
  name: 'mv',
  data() {
    return {
      id: '',
      // 总条数
      total: 20,
      // 页码
      page: 1,
      // 页容量
      limit: 10,

      // mvVIDEO: 'https://nie.v.netease.com/r/video/20180531/44f868de-deef-4409-8325-3bb3b5567f2c.mp4'
      mvVIDEO: '',

      mvs: [],
      detail: {},

      hotComments: [],
      comments: []
    };
  },
  async created() {
    this.id = this.$route.query.id;
    
    const res = await MVURL(this.id);
    this.mvVIDEO = res.data.url;

    const res2 = await MVSIMI(this.id);
    this.mvs = res2.mvs;

    const res3 = await MVDetail(this.id);
    this.detail = res3.data;   
    
    this.MVcomments()
  },
  methods: {
    async MVcomments() {
      const res = await MVcomment(this.id, this.limit, (this.page - 1) * this.limit);
      this.comments = res.comments
      this.hotComments = res.hotComments
      this.total = res.total
    },
    handleCurrentChange(val) {
      this.page = val;
      this.MVcomments()
    }
  }
};
</script>

<style></style>
